package com.sentiment.jsparser;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;   
   
/**  
 * Created with IntelliJ IDEA.  
 * User: lsz  
 * Date: 14-4-22  
 * Time: 下午1:17  
 * utils for http  
 */   
public class PhantomjsTest implements Runnable{
	private String url;
	public PhantomjsTest(String url) {
		// TODO Auto-generated constructor stub
		this.url = url;
	}
    public static String getAjaxCotnent(String url) throws IOException {   
        Runtime rt = Runtime.getRuntime();   
        Process p = rt.exec("D:/phantomjs-2.0.0-windows/bin/phantomjs.exe E:/check_sentiment/src/com/sentiment/phantomjs/phantomjsPort.js "+url);//这里我的codes.js是保存在c盘下面的phantomjs目录   
        InputStream is = p.getInputStream();   
        BufferedReader br = new BufferedReader(new InputStreamReader(is));   
        StringBuffer sbf = new StringBuffer();   
        String tmp = "";   
        while((tmp = br.readLine())!=null){   
            sbf.append(tmp);   
        }   
        //System.out.println(sbf.toString());   
        return sbf.toString();   
    }   
   
    public static void main(String[] args) throws IOException {   
    	ExecutorService exec = Executors.newCachedThreadPool();
		exec.execute(new PhantomjsTest("http://news.163.com/api/15/1019/21/B6AOC9DE00014SEH.html"));
		exec.execute(new PhantomjsTest("http://news.163.com/15/1020/10/B6C77SPU0001121M.html"));
		exec.execute(new PhantomjsTest("http://news.163.com/15/1020/10/B6C6IV8500011229.html"));
		
    }

	@Override
	public void run() {
		// TODO Auto-generated method stub
		PhantomjsCore core = new PhantomjsCore();
		System.out.println(core.parser(url));
	}   
    
}   
